package com.teach.basic.service.impl;

import com.teach.basic.model.dto.AssociatorDTO;
import com.teach.basic.model.po.Associator;
import com.teach.basic.dao.AssociatorDao;
import com.teach.basic.service.AssociatorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
/**
 * <p>
 *  会员表 服务实现类
 * </p>
 * @version 1.0
 * @author hzz
 * @since 2020-02-18
 */
@Service
@Log4j2
public class AssociatorServiceImpl extends ServiceImpl<AssociatorDao, Associator> implements AssociatorService {
    @Autowired
    private AssociatorDao associatorDao;
    public List<Associator> getList(Map<String,Object> param){
        return baseMapper.selectByMap(param);
    }
    @Transactional(rollbackFor = Exception.class)
    public String register(AssociatorDTO associator){
        Associator exit=associatorDao.selectByOpenId(associator.getOpenid());
        if(exit!=null&&exit.getId()!=null){
            return exit.getId();
        }
        try{
            associatorDao.insertSelective(associator);
        }catch (Exception e){
            associator.setName("老大");
            associatorDao.insertSelective(associator);
        }
        return associator.getId();
    }
    public Associator login(String openid){
        return associatorDao.selectByOpenId(openid);
    }
}
